﻿using CuoiHoi.Business;
using CuoiHoi.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;


namespace CuoiHoi.UserControls
{
    public partial class ChiTietDanhMuc : System.Web.UI.UserControl
    {
        public ETinTuc TinTuc;
        public ETheLoai TheLoai;
        protected void Page_Load(object sender, EventArgs e)
        {
            int idTinTuc = int.Parse(Page.RouteData.Values["Id"].ToString());
            string Title = Page.RouteData.Values["Title"].ToString();
            int idDanhMuc = int.Parse(Page.RouteData.Values["IdDanhMuc"].ToString());
            string TitleDanhMuc = Page.RouteData.Values["TitleDanhMuc"].ToString();

            TinTuc = BTinTuc.SelectByID(idTinTuc);
            TheLoai = BTheLoai.SelectByID(idDanhMuc);

            if (TinTuc.TieuDe != null)
            {
                if (Router.NonUnicode(TinTuc.TieuDe) != Title || Router.NonUnicode(TheLoai.TenTheLoai) != TitleDanhMuc)
                    Response.RedirectToRoute("ChiTietDanhMuc",
                        new
                        {
                            Title = Router.NonUnicode(TinTuc.TieuDe),
                              Id = TinTuc.idTinTuc,
                            TitleDanhMuc = Router.NonUnicode(TheLoai.TenTheLoai),
                              IdDanhMuc = idDanhMuc 
                        });
            }
            else
                Response.RedirectToRoute("Error");
        }
    }
}